package com.simas.screen;

//import com.simas.component.CellButton;
//import com.simas.component.CustomButton;
import com.simas.common.CommonFunction;
import com.simas.common.CommonMenu;
import com.simas.common.CustomResources;
import com.simas.info.CallInfoServlet;
import com.simas.component.CellButton;
//import com.simas.common.CustomResources;
//import com.simas.common.DeletePolisInfo;
//import com.simas.common.OpenInfoScreen;
//import com.simas.common.OpenPolisScreen;
//import com.simas.common.info.CallInfoServlet;
//import com.simas.component.GridFieldManager;

import net.rim.device.api.system.Bitmap;
//import net.rim.device.api.system.Display;
//import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
//import net.rim.device.api.ui.Font;
//import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Keypad;
//import net.rim.device.api.ui.Manager;
//import net.rim.device.api.ui.component.BitmapField;
//import net.rim.device.api.ui.component.Dialog;
//import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.Menu;
//import net.rim.device.api.ui.component.ObjectChoiceField;
//import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.Background;
import net.rim.device.api.ui.decor.BackgroundFactory;

public class XmlINFOScreen extends MainScreen implements FieldChangeListener {
	
	CommonFunction cf = new CommonFunction();
	CustomResources cr = new CustomResources();
	private CellButton btHome;
	private CellButton btInfoRS;
	private CellButton btInfoPersh;
	private CellButton btInfoTesti;
	private CellButton btInfoSimas;
	private LabelField lblSeparator1;
	private LabelField lblSeparator2;
	private LabelField lblSeparator3;
//	private LabelField lblSeparator4;
	
	/**
     * Menambah Menu Close
     */
    protected void makeMenu( Menu menu, int instance ) {
		CommonMenu cm = new CommonMenu(this);
		menu.add(cm._welcomeScreen);
	}
	   
    /**
     * Action utk Back Button
     */
    protected boolean keyDown(int keycode, int status)  {
		if(Keypad.key(keycode) == Keypad.KEY_ESCAPE) {
			CommonMenu cm = new CommonMenu(this);
			cm.welcomeScreen();
			return true;
		}
		return false;
	}
	
    /**
     * Action Listener
     */
	public void fieldChanged(Field field, int context) {
		if (field == btHome) {
			CommonMenu cm = new CommonMenu(this);
			cm.welcomeScreen();
		} else if (field == btInfoRS) {
			fnViewInfoScreen(1);
		} else if (field == btInfoPersh) {
			fnViewInfoScreen(2);
		} else if (field == btInfoTesti) {
			fnViewInfoScreen(3);
		} else if (field == btInfoSimas) {
			fnViewInfoScreen(4);
		}
	}
	
	private void fnViewInfoScreen(int intJnsInfo) {
		CallInfoServlet cis = new CallInfoServlet();
		cis.fnCallInfoServlet(this, intJnsInfo);
	}
	
	public XmlINFOScreen() {
		cr.getCustomFont(8);
		
		Bitmap resizeBitmap = cf.getScaledBitmapImage(cr.getImageURL("bgSimasInfo.png"));
		Background bg = BackgroundFactory.createBitmapBackground(resizeBitmap, 
																 Background.POSITION_X_LEFT, 
																 Background.POSITION_Y_TOP, 
																 Background.REPEAT_NONE);

		VerticalFieldManager vfm = new VerticalFieldManager(Field.USE_ALL_WIDTH);
		vfm.setBackground(bg);
		vfm.setFont(cr.getCustomFont(4));
		for (int a=1; a<=7; a++) {
			vfm.add(new LabelField(" ", Field.USE_ALL_WIDTH));
		}
		
		btHome = new CellButton("Home", Integer.parseInt("000000", 16), 
				 Integer.parseInt("FFCC33", 16), 
				 0, null, 0, 0, 0, 0);
		btHome.setFont(cr.getCustomFont());
		btHome.setChangeListener(this);
		
		btInfoRS = new CellButton("Rumah Sakit", Integer.parseInt("000000", 16), 
				 Integer.parseInt("FFCC33", 16), 
				 0, null, 0, 0, 0, 0);
		btInfoRS.setFont(cr.getCustomFont());
		btInfoRS.setChangeListener(this);
		
		btInfoPersh = new CellButton("Perusahaan", Integer.parseInt("000000", 16), 
				 Integer.parseInt("FFCC33", 16), 
				 0, null, 0, 0, 0, 0);
		btInfoPersh.setFont(cr.getCustomFont());
		btInfoPersh.setChangeListener(this);
		
		btInfoTesti = new CellButton("Testimonial", Integer.parseInt("000000", 16), 
				 Integer.parseInt("FFCC33", 16), 
				 0, null, 0, 0, 0, 0);
		btInfoTesti.setFont(cr.getCustomFont());
		btInfoTesti.setChangeListener(this);
		
//		btInfoSimas = new CellButton("Simas", Integer.parseInt("000000", 16), 
//				 Integer.parseInt("FFCC33", 16), 
//				 0, null, 0, 0, 0, 0);
//		btInfoSimas.setFont(cr.getCustomFont());
//		btInfoSimas.setChangeListener(this);
		
		lblSeparator1 = new LabelField(" | ", Field.FIELD_LEFT);
		lblSeparator1.setFont(cr.getCustomFont());
		
		lblSeparator2 = new LabelField(" | ", Field.FIELD_LEFT);
		lblSeparator2.setFont(cr.getCustomFont());
		
		lblSeparator3 = new LabelField(" | ", Field.FIELD_LEFT);
		lblSeparator3.setFont(cr.getCustomFont());
		
//		lblSeparator4 = new LabelField(" | ", Field.FIELD_LEFT);
//		lblSeparator4.setFont(cr.getCustomFont());
		
//		HorizontalFieldManager hfmButton = new HorizontalFieldManager(Field.FIELD_HCENTER);
//		hfmButton.add(btHome);
		//hfmButton.add(lblSeparator1);
		
		HorizontalFieldManager hfmButton1 = new HorizontalFieldManager(Field.FIELD_HCENTER);
		hfmButton1.add(btHome);
		hfmButton1.add(lblSeparator1);
		hfmButton1.add(btInfoRS);
		hfmButton1.add(lblSeparator2);
		hfmButton1.add(btInfoPersh);
		hfmButton1.add(lblSeparator3);
		hfmButton1.add(btInfoTesti);
//		hfmButton1.add(lblSeparator4);
//		hfmButton1.add(btInfoSimas);
		
//		vfm.add(hfmButton);
		vfm.add(hfmButton1);
		
		for (int a=1; a<=17; a++) {
			vfm.add(new LabelField(" ", Field.USE_ALL_WIDTH));
		}
		
		add(vfm);
	}
}
